var bip39 = require('bip39')
var hdkey = require('ethereumjs-wallet/hdkey')
var util = require('ethereumjs-util')
var Tx = require('ethereumjs-tx');
var keythereum = require("keythereum");
var Web3 = require('web3');


//初始化过程
//var Web3 = require('web3');

//if (typeof web3 !== 'undefined') {
//  web3 = new Web3(web3.currentProvider);
//} else {
//  // set the provider you want from Web3.providers
//  //web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/H2RvEhIXzZSxx73jLtcZ"));
//  web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/H2RvEhIXzZSxx73jLtcZ"));
//}
var web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/H2RvEhIXzZSxx73jLtcZ"))
//var ss = web3.sha3("transfer(address,uint256)").substr(2,8)
//console.log(ss)
//return
var privateKey = "3b4d287748b3c38cb85b07b8850899914b8e72b56603dec93ff607f01e49b6e8"
const txParams = {
  nonce: '0x2b',
  gasPrice: '0x98bca5a00', //1 Gwei（= 1000000000 = 0x3B9ACA00）
  gasLimit: '0x2EEEE0',
  to: '0xf79D7D43BbAe5f64a8B2EF3bee7Cc4CfbCA5d4d7', 
  value: '0x00', 
  data: '0xa9059cbb000000000000000000000000b52Aa890a5a9A56a1FDBCc62968B885B92Da7efF'+'0000000000000000000000000000000000000000000000000010000000000000',
  // EIP 155 chainId - mainnet: 1, ropsten: 3
  chainId: 3
}

//
const tx = new Tx(txParams)
tx.sign(Buffer.from(privateKey,'hex'))
const serializedTx = tx.serialize()
console.log(serializedTx)
web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function(err, hash) {
    console.log(err)
    console.log(hash); //0x03df36e41621c028fbe863ec5bc12c820fe6725eb13ca7881a8f0232dc3dce30
});

//console.log(serializedTx.toString('hex'))


//f86a808609184e72a00082271094976f596fbc70a66e655e2b624d4ff52300eb1eee85302e303031802aa08de49b889365a45af87d843d14688418680a3a4c9b0590f00f028373791aa860a02f575b27b842c3edf03e052defc3a7e206bca3bd0713c12166689a53759f3d4c

